package sound;

import java.util.Observable;
import java.util.Observer;

import universe.Game;

public class GameSound implements Observer {

	private Game		theGame;

	public GameSound(Game pGame) {
		this.setGame(pGame);
		this.getGame().addObserver(this);

	}

	@Override
	public void update(Observable o, Object arg) {
		if(application.Utils.soundActivated){
			if(arg.equals("deletedLines")){
				Player oPlayer = new Player(sound.Utils.soundRemoveCompletedLine, false);
				oPlayer.resume();
			}
			else if(arg.equals("nextLevel")){
				Player oPlayer = new Player(sound.Utils.soundNextLevel, false);
				oPlayer.resume();
			}
			else if(arg.equals("fourLines")){
				Player oPlayer = new Player(sound.Utils.soundFourLines, false);
				oPlayer.resume();
			}
			else if(arg.equals("fixedBlock")){
				Player oPlayer = new Player(sound.Utils.soundFixedBlock, false);
				oPlayer.resume();
			}
			else if(arg.equals("gamePause")){
				//System.out.println("update gamesound gamepaused");
				if(theGame.isGamePaused()){
					theGame.getBackgroundSound().pause();
				}
				else{
					theGame.getBackgroundSound().resume();
				}
			}
			else if(arg.equals("gameOverSound")){
				theGame.getBackgroundSound().killSound();
				Player gameOverSound = new Player(sound.Utils.gameOverTone, false);
				gameOverSound.resume();
			}
		}
	}

	public Game getGame() {
		return theGame;
	}

	public void setGame(Game pGame) {
		this.theGame = pGame;
	}

}